<?php
/**
 * dao seriesdao
 * @package app-drama_lib_dao
 */
load_lib('/dao/basedao');
/**
 * dao seriesdao
 * @author pandajingjing
 * @package app-drama_lib_dao
 */
class dao_seriesdao extends dao_basedao{

	/**
	 * 得到节目列表
	 * @param array $p_arrParam
	 * @param int $p_intPage
	 * @param int $p_intPageSize
	 * @return array
	 */
	static function getSeriesList($p_arrParam,$p_intPage=1,$p_intPageSize=20){
		$strSQL='';
		$arrParam=array();
		if(isset($p_arrParam['CLASSID'])){
			$strSQL.=' and CLASSID=:CLASSID';
			$arrParam['CLASSID']=$p_arrParam['CLASSID'];
		}
		if(isset($p_arrParam['TYPEID'])){
			$strSQL.=' and TYPEID=:TYPEID';
			$arrParam['TYPEID']=$p_arrParam['TYPEID'];
		}
		if(isset($p_arrParam['RATIOID'])){
			$strSQL.=' and RATIOID=:RATIOID';
			$arrParam['RATIOID']=$p_arrParam['RATIOID'];
		}
		if(isset($p_arrParam['SAW'])){
			$strSQL.=' and SAW=:SAW';
			$arrParam['SAW']=$p_arrParam['SAW'];
		}
		if(isset($strSQL[0])){
			$strSQL=substr($strSQL,4);
		}
		$objORM=parent::getORM('drama_series','drama_db');
		$intTotal=$objORM->getCnt($strSQL,$arrParam);
		load_lib('/util/page');
		$arrPage=util_page::getPage($p_intPage,$p_intPageSize,$intTotal);
		if(isset($p_arrParam['SORT'])){
			$objORM->setOrder($p_arrParam['SORT']);
		}
		$objORM->setStart(($arrPage['CURRENTPAGE']['INDEX']-1)*$arrPage['PAGESIZE']);
		$objORM->setRow($arrPage['PAGESIZE']);
		$arrData=$objORM->getList($strSQL,$arrParam);
		return array( 
				'DATA'=>$arrData,
				'PAGE'=>$arrPage 
		);
	}

	/**
	 * 获得节目详细信息
	 * @param int $p_intSerID
	 * @return array/null
	 */
	static function getSeriesDetail($p_intSerID){
		$objORM=parent::getORM('drama_series','drama_db');
		$objORM->SERID=$p_intSerID;
		return $objORM->getRow();
	}

	/**
	 * 添加节目
	 * @param array $p_arrParam
	 * @return int/false
	 */
	static function addSeries($p_arrParam){
		$p_arrParam['CREATETIME']=parent::getTime();
		return parent::addData('drama_series',$p_arrParam,'drama_db');
	}

	/**
	 * 保存节目
	 * @param array $p_arrParam
	 * @return int
	 */
	static function saveSeries($p_arrParam){
		$p_arrParam['UPDATETIME']=parent::getTime();
		return parent::updData('drama_series',$p_arrParam,'drama_db');
	}

	/**
	 * 获取节目种类列表
	 * @param $p_arrParam
	 * @return array
	 */
	static function getClassList($p_arrParam){
		$strSQL='';
		$arrParam=array();
		if(isset($strSQL[0])){
			$strSQL=substr($strSQL,0,4);
		}
		$objORM=parent::getORM('drama_dt_class','drama_db');
		if(isset($p_arrParam['SORT'])){
			$objORM->setOrder($p_arrParam['SORT']);
		}
		
		return $objORM->getList($strSQL,$arrParam);
	}

	/**
	 * 获取节目类型列表
	 * @param $p_arrParam
	 * @return array
	 */
	static function getTypeList($p_arrParam){
		$strSQL='';
		$arrParam=array();
		if(isset($strSQL[0])){
			$strSQL=substr($strSQL,0,4);
		}
		$objORM=parent::getORM('drama_dt_type','drama_db');
		if(isset($p_arrParam['SORT'])){
			$objORM->setOrder($p_arrParam['SORT']);
		}
		return $objORM->getList($strSQL,$arrParam);
	}
}